#ifndef _LOGGING_H_
#define _LOGGING_H_

#if defined(_MSC_VER)
#ifdef SIMPLELOGLIB_EXPORTS
#define SIMPLELOGLIB_API __declspec(dllexport)
#else
#define SIMPLELOGLIB_API __declspec(dllimport)
#endif
#else 
#define	SIMPLELOGLIB_API
#endif

#ifdef _USE_LOG4CXX
	#include <log4cxx/logger.h>
	#include <log4cxx/basicconfigurator.h>
	#include <log4cxx/propertyconfigurator.h>
	#include <log4cxx/helpers/exception.h>
	#define LOGINIT(file) log4cxx::PropertyConfigurator::configureAndWatch(file)
	#define LOGDEBUG(msg) LOG4CXX_DEBUG(log4cxx::Logger::getLogger("lib"), msg)
#ifdef _MSC_VER
	#pragma comment(lib,"log4cxx.lib")
#endif
#elif defined(_USE_SPDLOG)
#define SPDLOG_DEBUG_ON
#include "spdlog/spdlog.h"
#include <map>
#include <time.h>


struct SIMPLELOGLIB_API spdlog_instance
{
	static spdlog_instance& get_instance();

	std::string get_name();
	
	std::shared_ptr<spdlog::logger> get_logger();
	std::shared_ptr<spdlog::logger> get_console_logger();

	void init(const char* file);

	spdlog_instance();

	~spdlog_instance();

	void uninit();
};

#define LOGINIT(file) spdlog_instance::get_instance().init(file)
#define LOGUNINIT() spdlog_instance::get_instance().uninit()
#define LOGDEBUG(...) do{ \
			std::shared_ptr<spdlog::logger> logptr = spdlog_instance::get_instance().get_logger(); \
			SPDLOG_DEBUG(spdlog_instance::get_instance().get_console_logger(),__VA_ARGS__); \
			SPDLOG_DEBUG(logptr,__VA_ARGS__); \
}while (0);


#elif defined(_USE_GLOG)
	#include <glog/logging.h>
	#include <boost/property_tree/ptree.hpp>
	#include <boost/property_tree/ini_parser.hpp> 
	#include <string>
	class scoped_glog
	{
	public:
		scoped_glog(const char* file)
		{
			boost::property_tree::ptree pt;  
			boost::property_tree::ini_parser::read_ini(file, pt);
			std::string root=pt.get<std::string>("log4j.rootLogger","lib");
			google::InitGoogleLogging(root.c_str());
			FLAGS_log_dir = file;
		}
		~scoped_glog()
		{
			google::ShutdownGoogleLogging();
		}
	};
	#define LOGINIT(file) scoped_glog(file)
	#define LOGDEBUG(msg) LOG(DEBUG) << msg
#else
	#include <iostream>
	#include <sstream>
	SIMPLELOGLIB_API void  console_log(const std::string& slog);
	#define LOGINIT(file)
	#define LOGDEBUG(msg) {std::stringstream ss; ss<<msg<<std::endl;console_log(ss.str());}
	#define LOGUNINIT() 
#endif
#endif